import { BaseItem } from "../common/BaseItem";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { ItemData } from "../../resource/info/ItemData";
import { EDrug } from "../../../../Message/Public/EDrug";
import { Language } from "../../../../extend/language/Language";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { Cache } from "../../cache/Cache";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { SDrugBagInfo } from "../../../../Message/Game/SDrugBagInfo";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
type int = number;
//class DrugBagItem
    
    export  class DrugBagItem extends BaseItem
    {
        constructor()
        {
            super();
            this.setSize(17, 17);
            this.isDragAble = false;
            this.isDropAble = false;
            this.init();
            this.buttonMode = true;
            this.useHandCursor = true;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onThisClickHandler);
            return;
        }

        /* internal  */init(): void
        {
            this._bgBitmap = new Object /* flash.display.Bitmap */();
            this.addChildAt(this._bgBitmap, 0);
            freezingEffect.setMaskSize(18, 18);
            Dispatcher.addEventListener(EventName.ItemUse, this.onItemUseingHandler);
            return;
        }

        /* internal  */onThisClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        /* internal  */onItemUseingHandler(arg1: DataEvent): void
        {
            return;
        }

        public /* override */ set itemData(arg1: ItemData)
        {
            _itemData = arg1;
            return;
        }

        public /* override */ get toolTipData()
        {
            var loc4=0;
            var loc1="";
            var loc2="";
            var loc3=2000;
            var loc5=0;
            var loc6="";
            if (this.drugBagData) 
            {
                if (this.drugBagData.type != EDrug._EDrugLifeBag) 
                {
                    if (this.drugBagData.type == EDrug._EDrugManaBag) 
                    {
                        loc2 = Language.getString(50032);
                        loc4 = 1;
                    }
                }
                else 
                {
                    loc2 = Language.getString(50031);
                    loc4 = 0;
                }
                loc3 = ItemsUtil.getDrugEffectValue(this.drugBagData.type);
                if ((loc5 = Cache.instance.rune.getRuneEffectSelfDrugEffectCDTime(10000, loc4) / 1000) == 0) 
                {
                    loc6 = "";
                }
                else 
                {
                    loc6 = this.getRuneStr(loc5) + HTMLUtil.addColor(Language.getString(20693), "#FEAE58");
                }
                loc1 = loc1 + Language.getStringByParam(50033, loc2, loc2, loc2, loc2, loc3, loc2, this.drugBagData.remain, loc6);
                loc1 = HTMLUtil.addColor(loc1, "#B1efff") + "\r\r";
                return loc1;
            }
            return null;
        }

        public getRuneStr(arg1: number, arg2: string="#FEAE58"): string
        {
            if (arg1 > 0) 
            {
                return HTMLUtil.addColor(Language.getString(27526) + "＋" + arg1, arg2);
            }
            return HTMLUtil.addColor(Language.getString(27526) + "－" + (-arg1), arg2);
        }

        public get drugBagData(): SDrugBagInfo
        {
            return this._drugBagData;
        }

        public set drugBagData(arg1: SDrugBagInfo)
        {
            this._drugBagData = arg1;
            if (arg1) 
            {
                if (arg1.type != EDrug._EDrugLifeBag) 
                {
                    if (arg1.type == EDrug._EDrugManaBag) 
                    {
                        if (this._bagType != arg1.type) 
                        {
                            this._bagType = arg1.type;
                            this._bgBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.ManaDrugBag);
                            this._bgBitmap.width = 17;
                            this._bgBitmap.height = 17;
                            this.itemData = Cache.instance.timeCdCache.manaCD.itemData;
                        }
                        if (Cache.instance.timeCdCache.manaCD.isCoolDown == false) 
                        {
                            freezingEffect.cdTime = Cache.instance.timeCdCache.manaCD;
                        }
                    }
                }
                else 
                {
                    if (this._bagType != arg1.type) 
                    {
                        this._bagType = arg1.type;
                        this._bgBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.LifeDrugBag);
                        this._bgBitmap.width = 17;
                        this._bgBitmap.height = 17;
                        this.itemData = Cache.instance.timeCdCache.lifeCD.itemData;
                    }
                    freezingEffect.cdTime = Cache.instance.timeCdCache.changeShengLifeCd;
                }
            }
            else 
            {
                this._bgBitmap.bitmapData = null;
                freezingEffect.clearEffect();
                this._bagType = -1;
            }
            return;
        }

        public /* override */ setSize(arg1: number, arg2: number): void
        {
            super.setSize(arg1, arg2);
            if (freezingEffect) 
            {
                freezingEffect.x = 8;
                freezingEffect.y = 8;
            }
            return;
        }

        /* internal */ /* var */_bgBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_drugBagData: SDrugBagInfo;

        /* internal */ /* var */_bagType: int=-1;
    }
